package com.lemon.springboot.interceptor;

import com.lemon.springboot.entity.AccountVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 拦截器测试
 *
 * @Author liuli
 * @Date 2020/11/19 3:15
 */
public class LoginInterceptor implements HandlerInterceptor {
    static Logger logger = LoggerFactory.getLogger(LoginInterceptor.class);

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object account = request.getSession().getAttribute("account");
        if (account != null && account instanceof AccountVo) { // 已登录
            return true;
        } else { // 未登陆
            response.sendRedirect("/apm/login");
            return false;
        }

    }
}
